import MyPlugin from "../../../main";
import {
	recentOpenFileMdPath,
	recentOpenFilePath,
	recentSearchTagPath,
	searchPageIndex,
	sjzPluginPath
} from "../全局变量";

export function 插件初始化需要最先执行(this_:MyPlugin){
	// 创建插件目录
	this_.app.vault.adapter.exists(sjzPluginPath).then((exists) => {
		if (!exists){
			this_.app.vault.adapter.mkdir(sjzPluginPath)
		}
	})
	// 创建最近打开的文件.md文件
	this_.app.vault.adapter.exists(recentOpenFileMdPath).then((exists) => {
		if (!exists){
			this_.app.vault.adapter.write(recentOpenFileMdPath,"")
		}
	})
	// 创建最近打开的文件.json文件
	this_.app.vault.adapter.exists(recentOpenFilePath).then((exists) => {
		if (!exists){
			this_.app.vault.adapter.write(recentOpenFilePath,"")
		}else {
			this_.app.vault.adapter.read(recentOpenFilePath).then((content) => {
				if (content!== ""){
					this_.fileOpenCounts = JSON.parse(content);
				}
			})
		}
	})


	// 创建最近搜索标签文件.md文件
	this_.app.vault.adapter.exists(searchPageIndex).then((exists) => {
		if (!exists){
			this_.app.vault.adapter.write(searchPageIndex,"")
		}
	})

	// 创建最近搜索标签文件.json文件
	this_.app.vault.adapter.exists(recentSearchTagPath).then((exists) => {
		if (!exists){
			this_.app.vault.adapter.write(recentSearchTagPath,"")
		}else {
			this_.app.vault.adapter.read(recentSearchTagPath).then((content) => {
				if (content!== ""){
					this_.recentTags = JSON.parse(content);
				}
			})
		}
	})
}
